﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dotnet.Code
{
    public class ExcelToTableArgs : EventArgs
    {
        public int RowsCount { get; set; }
        public int Index { get; set; }
        public DataRow CurrDataRow { get; set; }
        public DataTable CurrDataTable { get; set; }
    }


    public abstract class ExcelDocument
    {
        private string _fileName = "";
        private EventHandler<ExcelToTableArgs> _excelToTable = null;
        protected ExcelDocument(string fileName)
        {
            _fileName = fileName;
        }
        protected string FileName { get => _fileName; set => _fileName = value; }

        public event EventHandler<ExcelToTableArgs> ExcelToTable
        {
            add { _excelToTable += value; }
            remove { _excelToTable -= value; }
        }
        protected virtual void OnExcelToTable(ExcelToTableArgs e)
        {
            var temp = System.Threading.Volatile.Read(ref _excelToTable);
            if (temp != null)
            {
                temp(this, e);
            }
        }
        public virtual DataSet ExcelToDataSet(string pwd = "")
        {
            return null;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sheetIndex">Sheet索引</param>
        /// <param name="password">Excel文档密码</param>
        /// <returns></returns>
        public abstract DataTable ExcelToDataTable(int sheet=0,string password = "");
    }
}
